//
// Created by dale on 2023/12/7.
//
#include <iostream>
#include <unordered_map>

int main() {
    std::cout << "Hello, World!" << std::endl;


    // 创建一个unordered_map
    std::unordered_map<std::string, int> umap;
    umap.insert(std::pair<std::string,int>("dale",15) );
    umap.insert(std::pair<std::string,int>("dale",14) );
    umap.insert_or_assign("dale",16);
    umap.emplace("ss",33);
    umap.emplace("ss",34);

    // 插入元素
    umap["Alice"] = 25;
    umap["Bob"] = 31;
    umap["Charlie"] = 42;
    umap["David"] = 19;

    // 遍历unordered_map
    for (const auto& pair : umap) {
        std::cout << "Key2: " << pair.first << ", Value: " << pair.second << std::endl;
    }
    std::cout<< "#####"<< std::endl;

    // 查找元素
    std::string key = "Bob";
    if (umap.find(key) != umap.end()) {
        std::cout << key << " found. Value: " << umap[key] << std::endl;
    } else {
        std::cout << key << " not found." << std::endl;
    }

    // 删除元素
    key = "Charlie";
    umap.erase(key);

    // 再次遍历unordered_map
    for (auto pair : umap) {
        std::cout << "Key: " << pair.first << ", Value: " << pair.second << std::endl;
    }

    return 0;
}
